<template>
	<view class="uni-tab-bar">
		<view class="scroll-wrap" >
			<scroll-view class="list" scroll-y @scrolltolower="loadMore()" :style="scrollViewHeight">
				<block v-for="(newsItem, newsIndex) in newsList" :key="newsIndex">
					<uni-media-list :data="newsItem"  @click="goDetail(newsItem)"></uni-media-list>
				</block>
				
			</scroll-view>
		</view>
	</view>
</template>
<script>
	
	import api from '../../api.js';
	import uniMediaList from '@/components/uni-media-list/uni-media-list.vue';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		friendlyDate
	} from '@/common/util.js';
	export default {
		components: {
			uniMediaList,
			uniLoadMore
		},
		
		data() {
			return {
				loadingText: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				scrollLeft: 0,
				refreshing: false,
				refreshText: '下拉可以刷新',
				newsList: [],
				page:1
			}
		},
		computed: {
			scrollViewHeight() {
				return 'height:' + (uni.getSystemInfoSync().windowHeight) + 'px';
			}
		},
		onLoad: function() {
			this.getList();
		},
		methods: {
			getList() {
				this.loadingText = '加载中...';
				var that=this
				api.post({
					url: 'api/getNotice.do',
					data: {
						page: this.page,
						limit: 10
					},
					success(result) {
						if(result.code==0){
							this.loadingText='没有更多数据了';
							result.data.map((news) => {
								that.newsList.push({
									id: news.id,
									datetime: friendlyDate(news.createTime),
									title: news.title,
									content:news.content,
									source: news.type
								});
							});
							
						}else{
							this.loadingText='暂无数据';
						}
						
					}
				});
			},
			goDetail(detail) {
				uni.navigateTo({
					url: '/pages/notice/detail?query=' + encodeURIComponent(JSON.stringify(detail))
				});
			},
			dislike(tabIndex, newsIndex) {
				uni.showModal({
					content: '不感兴趣？',
					success: (res) => {
						if (res.confirm) {
							this.newsList[tabIndex].data.splice(newsIndex, 1);
						}
					}
				})
			},
			loadMore() {
				this.page++;
				this.getList();
			},
			onRefresh(event) {
				this.refreshText = '正在刷新...';
				this.refreshing = true;
				this.getList();
			}
		}
	}
</script>
<style>
	page {
		background-color: #FFFFFF;
		height: 100%;
		font-size: 11px;
		line-height: 1.8;
	}

	.uni-tab-bar {
		display: flex;
		flex: 1;
		flex-direction: column;
		overflow: hidden;
		height: 100%;
	}

	.uni-tab-bar .list {
		width: 750upx;
		height: calc(100% - 100upx);
	}

	.uni-swiper-tab {
		width: 100%;
		white-space: nowrap;
		line-height: 100upx;
		height: 100upx;
		border-bottom: 1px solid #c8c7cc;
		position: fixed;
		background: #FFFFFF;
		z-index: 999;
		top: var(--window-top);
		left: 0;
	}

	.swiper-tab-list {
		font-size: 30upx;
		width: 150upx;
		display: inline-block;
		text-align: center;
		color: #555;
	}

	.uni-tab-bar .active {
		color: #007AFF;
	}

	.uni-tab-bar .swiper-box {
		flex: 1;
		width: 100%;
		height: calc(100% - 100upx);
		overflow: scroll;
	}

	.uni-tab-bar-loading {
		text-align: center;
		padding: 20upx 0;
		font-size: 14px;
		color: #CCCCCC;
	}
</style>
